<template>
  <div class="app-container">
    <!-- 个人信息 -->
    <el-form ref="checkForm" :model="userInfo" label-width="100px">
      <!--手机 聘用形式  -->
      <el-row class="inline-info">
        <el-col :span="12">
          <el-form-item label="部门" required>
            <el-input v-model="userInfo.departmentName" @focus="showtree=true" />
            <Tree :is-show.sync="showtree" class="treeBox" @updateDept="updateDept" />
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 工号 入职时间 -->
      <el-row class="inline-info">
        <el-col :span="12">
          <el-form-item label="入职时间">
            <el-date-picker
              v-model="userInfo.timeOfEntry"
              type="date"
              class="inputW"
              value-format="yyyy-MM-dd"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 员工照片 -->
      <el-row class="inline-info">
        <el-col :span="12">
          <el-form-item label="员工头像">
            <!-- 放置上传图片 -->
            <UploadImg :photo.sync="userInfo.staffPhoto" />
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 保存个人信息 -->
      <el-row class="inline-info" type="flex" justify="center">
        <el-col :span="12">
          <el-button type="primary" @click="updateInfo">保存更新</el-button>
          <el-button @click="$router.back()">返回</el-button>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import { saveUserDetailById } from '@/api/employee.js'
import { parseTime } from '@/utils/index.js'
export default {
  props: {
    userInfo: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      showtree: false
    }
  },
  methods: {
    updateDept(dept) {
      this.userInfo.departmentName = dept
    },
    updateInfo() {
      this.$refs.checkForm.validate(async(isok) => {
        if (isok) {
          this.userInfo.timeOfEntry = parseTime(this.userInfo.timeOfEntry, '{y}-{m}-{d}')
          await saveUserDetailById(this.userInfo)
          this.$message.success('操作成功！')
          this.$router.back()
        }
      })
    }
  }

}
</script>

<style lang="scss" scoped>

</style>
